﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace DLL.SupplyDemand
{
	/// <summary>
	/// 视图控制类
	/// </summary>
	/// <![CDATA[2014-8-7 17:52:59]]>
	public class View : DLL.ShowLayer.FormView
	{
		private Component clsthisComp;

		#region 添加、修改
		private DropDownList ddlType = new DropDownList();
		private TextBox tbShowDate = new TextBox();
		private FileUpload fUpload = new FileUpload();
		#endregion 添加、修改

		#region 查询

		#endregion 查询

		#region 浏览

		#endregion 浏览

		#region 构造函数
		/// <summary>
		/// 视图类构造函数
		/// </summary>
		/// <![CDATA[2014-9-4 9:10:26]]>
		public View(System.Web.UI.Page page)
			: base(page)
		{
			clsthisComp = new Component(page);

			clsComp = clsthisComp;

			clsControls.ShowSupplyDemandType(ddlType);
			tbShowDate.Text = System.DateTime.Now.ToShortDateString();
			tbShowDate.Attributes.Add("onClick", "popUpCalendar(this, this, 'yyyy-mm-dd')");
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("类别", "DropDownList", ddlType, "int", "nType"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("时间", "TextBox", tbShowDate, "string", "strShowDate"));
			listAddEdit.Add(new TonyNet4V1.Structs.TitleControlEntity("内容", "FileUpload", fUpload, "", ""));
		}
		#endregion 构造函数

		#region 类型转换

		protected override TonyNet4V1.EntityBase GetEntity()
		{
			return new Entity();
		}

		protected override TonyNet4V1.QueryEntityBase GetQuery()
		{
			return new QueryEntity();
		}

		protected override TonyNet4V1.ComponentBase GetComponent()
		{
			return clsthisComp;
		}

		#endregion 类型转换

		/// <summary>
		/// 添加供求信息
		/// </summary>
		/// <returns></returns>
		public override bool Add()
		{
			//return base.Add();
			Entity clsSupplyDemand = new Entity();
			FileContent.Component clsFileContentComp = new FileContent.Component(page);
			FileContent.Entity clsFileContent = new FileContent.Entity();

			ControlToEntity(clsSupplyDemand, listAddEdit);

			clsFileContent = clsFileContentComp.Add(fUpload);

			if (clsFileContent != null)
			{
				clsSupplyDemand.Name = clsFileContent.FileName;
				clsSupplyDemand.DateTime = clsFileContent.DateTime;
				clsSupplyDemand.FileContentID = clsFileContent.ID;
			}
			else
			{
				clsSupplyDemand.DateTime = System.DateTime.Now.ToString();
			}
			clsSupplyDemand.UserID = nUserID;
			clsSupplyDemand.DepartmentID = nDepartmentID;

			return clsthisComp.Add(clsSupplyDemand);
		}

		/// <summary>
		/// 显示登录用户所在单位的供求信息
		/// </summary>
		/// <param name="gv"></param>
		public void ShowByDepartmentID(GridView gv)
		{
			gv.DataSource = clsthisComp.QueryByDepartmentID(nDepartmentID);
			gv.DataKeyNames = new string[] { "ID" };
			gv.DataBind();
		}

	}
}
